import { useI18n } from '/@/hooks/web/useI18n';
import { BasicColumn, BasicTableProps, FormProps } from '/@/components/Table';
import { companyTreeData } from '/@/api/sys/company';
import { basVenListData } from '/@/api/bas/ven/basVen';
import { basVenClsTreeData } from '/@/api/bas/ven/basVenCls';


const { t } = useI18n('bas.ven.basVen');

const modalProps = {
  title: t('供应商选择'),
};

const searchForm: FormProps = {
  baseColProps: { lg: 6, md: 8 },
  labelWidth: 100,
  schemas: [
    {
      label: t('地区分类'),
      field: 'pkAreacl',
      fieldLabel: 'basVenCls.clsName',
      component: 'TreeSelect',
      componentProps: {
        api: basVenClsTreeData,
        allowClear: true,
      },
    },
    {
      label: t('客商编码'),
      field: 'cuscode',
      component: 'Input',
    },
    {
      label: t('客商名称'),
      field: 'cusname',
      component: 'Input',
    },
    {
      label: t('客商简称'),
      field: 'shortName',
      component: 'Input',
    },
    {
      label: t('公司名称'),
      field: 'pkCorp',
      component: 'TreeSelect',
      componentProps: {
        api: companyTreeData,
        allowClear: true,
      },
      ifShow: false,
    },
    {
      label: t('状态'),
      field: 'status',
      component: 'Select',
      componentProps: {
        dictType: 'sys_search_status',
        allowClear: true,
      },
    },
  ],
};

const tableColumns: BasicColumn[] = [
  {
    title: t('客商编码'),
    dataIndex: 'cuscode',
    key: 'a.cuscode',
    sorter: true,
    width: 130,
    align: 'left',
    slot: 'firstColumn',
  },
  {
    title: t('客商名称'),
    dataIndex: 'cusname',
    key: 'a.cusname',
    sorter: true,
    width: 230,
    align: 'left',
  },
  {
    title: t('客商简称'),
    dataIndex: 'shortName',
    key: 'a.short_name',
    sorter: true,
    width: 230,
    align: 'left',
  },
  {
    title: t('地区分类'),
    dataIndex: 'basVenCls.clsName',
    key: 'a.pk_areacl',
    sorter: true,
    width: 130,
    align: 'left',
  },
  {
    title: t('公司名称'),
    dataIndex: 'company.companyName',
    key: 'a.pk_corp',
    sorter: true,
    width: 130,
    align: 'left',
    ifShow: false,
  },
  {
    title: t('状态'),
    dataIndex: 'status',
    width: 100,
    align: 'center',
    dictType: 'sys_search_status',
  },
];

const tableProps: BasicTableProps = {
  api: basVenListData,
  beforeFetch: (params) => {
    params['isAll'] = true;
    return params;
  },
  columns: tableColumns,
  formConfig: searchForm,
  rowKey: 'cuscode',
};

export default {
  modalProps,
  tableProps,
  itemCode: 'cuscode',
  itemName: 'cusname',
  isShowCode: true,
};


